package com.example.demo.controller;

import com.example.demo.VO.Result;
import com.example.demo.entity.Paper;
import com.example.demo.entity.PaperHistory;
import com.example.demo.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (PaperHistory)表控制层
 *
 * @author hjl
 * @since 2020-11-30 22:43:03
 */
@CrossOrigin
@RestController
@RequestMapping("paperHistory")
public class PaperHistoryController {

    /**
     * 服务对象
     */
    @Autowired
    private PaperHistoryService paperHistoryService;
    @Autowired
    private PaperService paperService;
    @Resource
    private ChoiceService choiceService;
    @Resource
    private JudgmentService judgmentService;
    @Resource
    private BlankService blankService;
    @Resource
    private Short1Service short1Service;


    /**
     * 根据属性查询 （当参数为空时候）查询所有
     *
     * @param paperHistory
     * @return
     */
    @GetMapping("list")
    public ResponseEntity<List<PaperHistory>> query(@RequestBody(required = false) PaperHistory paperHistory) {
        return ResponseEntity.ok(paperHistoryService.queryByExample(paperHistory));
    }

    /**
     * 插入一条数据
     *
     * @param paperHistory
     * @return
     */
    @PostMapping("add")
    public ResponseEntity<List<PaperHistory>> add(@RequestBody PaperHistory paperHistory) {
        paperHistoryService.insert(paperHistory);
        return ResponseEntity.ok(paperHistoryService.queryByExample(new PaperHistory()));
    }

    /**
     * 根据主键更新数据
     *
     * @param paperHistory
     * @return
     */
    @PutMapping("update")
    public ResponseEntity<List<PaperHistory>> update(@RequestBody PaperHistory paperHistory) {
        paperHistoryService.update(paperHistory);
        return ResponseEntity.ok(paperHistoryService.queryByExample(new PaperHistory()));
    }

    /**
     * 根据主键删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("del/{id}")
    public ResponseEntity<List<PaperHistory>> delete(@PathVariable("id") Integer id) {
        paperHistoryService.deleteById(id);
        return ResponseEntity.ok(paperHistoryService.queryByExample(new PaperHistory()));
    }



}